﻿using System;

namespace JanusLibAing.AutoSave
{
    public abstract class DataItemInteger : IDataItem
    {
        private int intValue;

        /// <summary>
        /// Initializes a new instance of the <see cref="DataItemInteger"/> class.
        /// </summary>
        /// <param name="value">The value.</param>
        protected DataItemInteger(int value)
        {
            intValue = value;
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return ItemValue.ToString();
        }

        public void ParseValue(string importValue)
        {
            try
            {
                intValue = int.Parse(importValue);
            }
            catch (Exception)
            {
                // do nothing
            }
        }

        /// <summary>
        /// Gets the item name.
        /// </summary>
        /// <value>The name.</value>
        public abstract string Name { get; }

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        public object Value
        {
            get { return intValue; }
            set { intValue = (int) value; }
        }

        /// <summary>
        /// Gets or sets the item value.
        /// </summary>
        /// <value>The item value.</value>
        public int ItemValue
        {
            get { return intValue; }
            set { intValue = value; }
        }
    }
}